<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/9
 * Time: 下午3:15
 */

namespace app\admin\controller;


use think\Request;

class Brand extends Auth
{
    /**
     * @purpose 创建品牌
     * @param Request $request
     * @return array
     * @throws \Exception
     */
    public function create (Request $request)
    {
        $data = $request->post();
        return \app\admin\logic\Brand::create($data);
    }

    /**
     * @purpose 更新数据
     * @param Request $request
     * @return array
     */
    public function edit (Request $request)
    {
        $data = $request->post();
        return \app\admin\logic\Brand::edit($data);
    }

    /**
     * @purpose 删除品牌
     * @param Request $request
     * @return array
     */
    public function delete (Request $request)
    {
        $id     = $request->post('id');
        return  \app\admin\logic\Brand::delete($id, self::$user_info['uid']);
    }

    /**
     * @purpose 对品牌进行排序
     * @param Request $request
     * @return array
     * @throws \Exception
     */
    public function sort (Request $request)
    {
        $sort   = $request->post();
        return \app\admin\logic\Brand::sort($sort);
    }

    /**
     * @purpose 获取品牌列表
     * @param Request $request
     * @return array
     */
    public function items (Request $request)
    {
        $page   = $request->get('page', 1);
        $size   = $request->get('size', 50);
        return \app\admin\logic\Brand::items([], $page, $size);
    }

    /**
     * @purpose 发布商品时获取品牌
     * @return array
     */
    public function itemByCreateGoods() {
        return \app\admin\logic\Brand::items([], 1, 10000, 'id,name,english,thumb');
    }
    /**
     * @purpose 通过ID获取单条信息
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function infoById (Request $request)
    {
        $id = $request->get('id');
        return \app\admin\logic\Brand::infoById($id);
    }
}